package olegroshka.src.com.bofa.olegroshka.decorator;

import java.math.BigDecimal;


public class BigDecimalDecorator implements Decorator<Object, Object> {
	private final int scale;
	
	public BigDecimalDecorator() {
		scale = 2;
	}

	public BigDecimalDecorator(int scale) {
		this.scale = scale;
	}

	public Object decorate(Object in) {
		if( in != null && !(in instanceof BigDecimal) ) {
			throw new IllegalArgumentException("Expected " + BigDecimal.class + " here was: " + in.getClass());
		}
		return in != null ? ((BigDecimal)in).setScale(scale) : BigDecimal.ZERO.setScale(scale);
	}
}